/*
 * Author: Alberto De Pena
 * Applied Algorithms
 * sync.cpp
*/
#include <iostream>
#include <fstream>
using namespace std;

void main()
{
    ifstream fin;
    ofstream fout;
	
    fin.open( "sync.in" );
    fout.open( "sync.out" );

    int i, n, hours, minutes, seconds, Seconds;
	int Sync[11], TimeSync[11];
    bool firstSync, syncAgain, Green;

    fin >> n;

    while( n > 0 )
    {
        for( i = 0; i < 11; i++ )
        {
            Sync[i] = 0;
            TimeSync[i] = 0;
        }

        for( i = 1; i <= n; i++ )
        {
            fin >> Sync[i];
            TimeSync[i] = Sync[i] - 5;
        }

        firstSync = false;
        syncAgain = false;
        for( Seconds = 0; Seconds < 86400 && !syncAgain; Seconds++ )
        {
            Green = true;
            if( !firstSync )
            {
                for( i = 1; i <= n; i++ )
                {
                    TimeSync[i] -= 1;
                    if( TimeSync[i] == 0 )
                        firstSync = true;
                }
            }
            else if( !syncAgain )
            {
                for( i = 1; i <= n; i++ )
                    if( TimeSync[i] <= 0 )
                        Green = false;
                
                if( !Green )
                {
                    for( i = 1; i <= n; i++ )
                    {
                        TimeSync[i] -= 1;
                        if( TimeSync[i] - 1 < (Sync[i] + 5) * -1 )
                            TimeSync[i] = Sync[i] - 5;
                    }
                }
                else
                    syncAgain = true;
            }
        }

        Seconds--;
        hours = Seconds / 3600;
        Seconds = Seconds % 3600;
        minutes = Seconds / 60;
        seconds = Seconds % 60;

        if( hours < 10 )
            fout << "0";

        fout << hours << ":";
        if( minutes < 10 )
            fout << "0";

        fout << minutes << ":";
        if( seconds < 10 )
            fout << "0";

        fout << seconds << endl;

        fin >> n;
    }

    fin.close();
    fout.close();
}

